#!/bin/sh

if [ "$1" = "" ]; then
	echo "Usage: $0 <snap-name>"
	echo "Example: $0 0000-installed"
	exit
fi

if [ "$1" = "rootfs" ]; then
	btrfs sub set-default /parent/rootfs
	echo
	echo 'Default:'
	btrfs sub get-default /
	exit
fi

if [ -d "/parent/rootfs" ]; then
	echo "/parent/rootfs exists, please rename it first!"
	exit
fi

btrfs sub snap "/parent/$1" "/parent/rootfs"
btrfs sub set-default /parent/rootfs

echo
echo 'Default:'
btrfs sub get-default /

